﻿using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public abstract class EatableObj : MonoBehaviour
{
    public float power = 0.1f;

    public Transform model => transform.GetChild(0);

    public bool dead;
}

public class Food : EatableObj
{
    public TextMeshPro value;

    public Renderer cRenderer;
    public float transScaleFactor = 3;

    public SizeType sizeType = SizeType.Money;

    //public Material[] colorMats;

    // Start is called before the first frame update
    void Start()
    {
        //transform.localScale = power * Vector3.one * transScaleFactor;
        
        if (value)
        {
            //value.text = Value2Show(power).ToString();
        }

    }
    
    private void OnTriggerStay(Collider other)
    {
        if (dead) return;

        if (other.TryGetComponent(out Player player))
        {
            OnTriggerPlayer(player);
            //AchievementCtrl.instance.AddOneValue(AchievementType.Eat30Food);
        }
    }

    private void OnTriggerPlayer(Player player)
    {
        dead = true;

        if (sizeType == SizeType.Money)
        {
            player.AddIncome((int)power);
            
            var pref = GameResourceManager.Load<GameObject>(GameResourceManager.pickMoneyFxPath);
            if (pref)
            {
                var fx = Instantiate(pref);
                fx.transform.position = transform.position;
                fx.AddComponent<DelayDestroy>();
            }
        }
        else if (sizeType == SizeType.Edu)
        {
            player.AddEduScore(power);
            
            var pref = GameResourceManager.Load<GameObject>(GameResourceManager.pickItemFxPath);
            if (pref)
            {
                var fx = Instantiate(pref);
                fx.transform.position = transform.position;
                fx.AddComponent<DelayDestroy>();
            }
        }

        gameObject.SetActive(false);
    }


    // Update is called once per frame
    void Update()
    {
        
    }
}
